#!/bin/bash

# 检查是否提供了输出目录参数
if [ -z "$1" ]; then
    echo "Usage: $0 <root_directory>"
    exit 1
fi

# 设置输出目录和 bag 文件目录
output_dir="$1/slam/odometry/"
bag_dir="$1/rawdata/metacam/data/"

# 检查 bag 文件目录是否存在
if [ ! -d "$bag_dir" ]; then
    echo "Error: Bag file directory does not exist: $bag_dir"
    exit 1
fi

# 获取排序后的 bag 文件列表
bag_files=$(find "$bag_dir" -name '*.bag' | sort | tr '\n' ' ')

# 检查是否找到了 bag 文件
if [ -z "$bag_files" ]; then
    echo "Error: No bag files found in directory: $bag_dir"
    exit 1
fi

# 打印 bag 文件列表
echo "Bag files to play:"
echo "$bag_files"

if [ "$#" -lt 2 ]; then
    USE_INTERPOLATION=False
else
    USE_INTERPOLATION=$2
fi
# 执行 roslaunch 命令并传递参数
roslaunch metacam_adapter run_fastlio.launch output_dir:="$output_dir" bag_files:="$bag_files" use_interpolation:=$USE_INTERPOLATION
